package com.yifeng.repo.base.constant;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 性别
 * Created by daibing on 2024/5/21.
 */
@Getter
@AllArgsConstructor
public enum GenderEnum {
    MALE(1, "男"),
    FEMALE(2, "女"),
    OTHER(3, "其他"),
    UNKNOWN(4, "未知"),
    ;

    @EnumValue
    @JsonValue
    private final Integer code;

    private final String name;

    private static final Map<Integer, GenderEnum> mappings = new HashMap<>(4);

    static {
        for (GenderEnum msgChannel : values()) {
            mappings.put(msgChannel.getCode(), msgChannel);
        }
    }

    public static GenderEnum resolve(Integer code) {
        return (code != null ? mappings.get(code) : null);
    }
}
